package com.atguigu.yygh.cmn.controller;

import com.atguigu.yygh.cmn.service.DictService;
 import com.atguigu.yygh.common.result.Result;
 import com.atguigu.yygh.model.cmn.Dict;
 import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@CrossOrigin
@Api(tags = "数据字典接口")
@RestController
@RequestMapping("/admin/cmn/dict")
public class DictController {


    @Autowired
     DictService dictService;
//    根据id查询子节点数据的列表
    @GetMapping("findChildData/{id}")
    public Result findChildData(@PathVariable Long id)
    {
     List<Dict> list= dictService.findChildData(id);
        System.out.println(list);
     return Result.ok(list);
    }
//    导出数据字典接口
    @GetMapping("exportData")
    public void exportDict(HttpServletResponse response)
    {
        dictService.exportDictData(response);

    }
//    导入数据字典
    @PostMapping("importData")
//    导入文件在springboot中使用multipartFile
    public  Result importDict(MultipartFile file)
    {
        dictService.importDictData(file);
        return Result.ok();
    }
}
